import QtQuick 1.0

Item {
    property bool paused : true

    id: clo
    width: map.width

    Image {
        id: sky
        source: "res/img/sky.png"
    }

    Image {
        id: clouds
        fillMode: Image.TileHorizontally
        source: "res/img/cloud.png"

        y: 40
    }

    Image {
        id: sun
        source: "res/img/sun.png"

        x: 30
        y: 45
    }

    Image {
        id: city
        fillMode: Image.TileHorizontally
        source: "res/img/city.png"

        y: 341
        x: 30
    }

    Component {
        id: chestCreation

        Chest { }
    }

    function createChest(xPos, hasItemIn) {
        chestCreation.createObject(map, { x: xPos, y: 461, z: 0, hasItem: hasItemIn});
    }

    /*Text {
          text: "Health:" + player.health + "\nStr:" + player.strength + "\nDef:" + player.defense + "\nAtck:";
          font.family: charlemagne.name
          font.pixelSize: 32
          x: 15
          y: 15
          color: "#694A23"

          visible: true
      }

    Text {
          text: "Health:" + enemy.health + "\nStr:" + enemy.strength + "\nDef:" + enemy.defense + "\nAtck:" + enemy.attacking;
          font.family: charlemagne.name
          font.pixelSize: 32
          x: 600
          y: 15
          color: "#694A23"

          visible: false
      }*/

    Interface {
        id: gameInterface
    }

    Map {
        source: "res/map/scenery01.tmx"
        id: map

        Player {
            id: player

            paused: clo.paused

            startX: 30
            startY: 470

            z: 1

            level: "cityLevel"
        }

        //generate randomly
        /*Chest {
            id: chest1
            x: 439
            y: 461
            z : 0
            hasItem: true
        }

        Chest {
            id: chest2
            x: 600
            y: 461
            z : 0
            hasItem: true
        }

        Chest {
            id: chest3
            x: 800
            y: 461
            z : 0
            hasItem: true
        }*/

        Component.onCompleted: {
            // adjust background
            clouds.width = width;
            city.width = width;
        }
    }

    /* Scroll: call it to scroll scene based on player's position */
    function scroll(amount) {
        map.x -= amount;
        clouds.x -= (amount / 6);
        city.x -= (amount / 2);

        sun.x -= (amount / 24);
    }

    function resetPositions() {
        // THIS FUNCTION NEEDS WORK!
        //scroll(map.width * 0.6);
        //var current = player.x;
        //console.debug("Reset from" + current + " to " + player.startX);

        player.x = player.startX;
        player.y = player.startY;

        //scroll((current - player.x - (game.width * 1.2)) * -1 );
        map.x = 0;
        clouds.x = 0;
        city.x = 0;
        sun.x = 0;
    }
}

